package com.visualexpress.wrapper.util;

public class IdHelp {
	int start_index;
	int end_index;
	int[] constans = new int[] { 7, 9, 5, 3, 2, 4, 6, 8 };
	public synchronized String getMailID() {

		if (start_index <= end_index) {
			String istr = new Integer(start_index).toString();
			while (!this.judgeNum(istr)) {
				start_index++;
				istr = new Integer(start_index).toString();
			}
			if (start_index <= end_index) {
				String zero = "";
				for (int j = 0; j < 9 - istr.length(); j++) {
					zero += "0";
				}
				String mailNum = "EW" + zero + istr + "CN";
				start_index++;
				return mailNum;
			} else
				return null;
		}
		return null;
	}

	public boolean judgeNum(String istr) {
		int sum = 0;
		for (int i = 0; i < istr.length() - 1; i++) {
			sum += constans[7-i] * (istr.charAt(i) - 48);
		}
		if ((11 - sum % 11) == (istr.charAt(istr.length() - 1) - 48))
			return true;
		else
			return false;
	}

	public int getStart_index() {
		return start_index;
	}

	public void setStart_index(int start_index) {
		this.start_index = start_index;
	}

	public int getEnd_index() {
		return end_index;
	}

	public void setEnd_index(int end_index) {
		this.end_index = end_index;
	}

}
